
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 05/27/2012 21:42:40
-- Generated from EDMX file: E:\Work\MyProject\Houode\HouodeFun\HoudeFun.TrainCenter.Model\DataModel.edmx
-- --------------------------------------------------

create database [HouodeDB];
GO

SET QUOTED_IDENTIFIER OFF;
GO
USE [HouodeDB];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------


-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------


-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'UserInfo'
CREATE TABLE [dbo].[UserInfo] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [UserName] nvarchar(32)  NULL,
    [NickName] nvarchar(32)  NULL,
    [LoginCode] nvarchar(32)  NULL,
    [DelFlag] smallint  NOT NULL,
    [SubTime] datetime  NOT NULL,
    [ModifiedDate] datetime  NOT NULL,
    [Gender] bit  NOT NULL,
    [Birthday] datetime  NOT NULL,
    [SingleStatus] smallint  NOT NULL,
    [Position] nvarchar(32)  NOT NULL,
    [WorkStatus] smallint  NOT NULL,
    [Email] nvarchar(128)  NOT NULL,
    [Avatar] nvarchar(128)  NOT NULL
);
GO

-- Creating table 'ProvinceInfo'
CREATE TABLE [dbo].[ProvinceInfo] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [PName] nvarchar(16)  NOT NULL,
    [PType] smallint  NOT NULL,
    [AddressInfoID] int  NOT NULL
);
GO

-- Creating table 'CityInfo'
CREATE TABLE [dbo].[CityInfo] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [CityName] nvarchar(32)  NOT NULL,
    [CityType] smallint  NOT NULL,
    [ProvinceInfoID] int  NOT NULL,
    [AddressInfoID] int  NOT NULL
);
GO

-- Creating table 'AddressInfo'
CREATE TABLE [dbo].[AddressInfo] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Street] nvarchar(128)  NULL,
    [Remark] nvarchar(max)  NULL,
    [SubTime] datetime  NOT NULL,
    [UserInfoID] int  NOT NULL,
    [AddressType] smallint  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ID] in table 'UserInfo'
ALTER TABLE [dbo].[UserInfo]
ADD CONSTRAINT [PK_UserInfo]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'ProvinceInfo'
ALTER TABLE [dbo].[ProvinceInfo]
ADD CONSTRAINT [PK_ProvinceInfo]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'CityInfo'
ALTER TABLE [dbo].[CityInfo]
ADD CONSTRAINT [PK_CityInfo]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'AddressInfo'
ALTER TABLE [dbo].[AddressInfo]
ADD CONSTRAINT [PK_AddressInfo]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [UserInfoID] in table 'AddressInfo'
ALTER TABLE [dbo].[AddressInfo]
ADD CONSTRAINT [FK_UserInfoAddressInfo]
    FOREIGN KEY ([UserInfoID])
    REFERENCES [dbo].[UserInfo]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserInfoAddressInfo'
CREATE INDEX [IX_FK_UserInfoAddressInfo]
ON [dbo].[AddressInfo]
    ([UserInfoID]);
GO

-- Creating foreign key on [ProvinceInfoID] in table 'CityInfo'
ALTER TABLE [dbo].[CityInfo]
ADD CONSTRAINT [FK_CityInfoProvinceInfo]
    FOREIGN KEY ([ProvinceInfoID])
    REFERENCES [dbo].[ProvinceInfo]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CityInfoProvinceInfo'
CREATE INDEX [IX_FK_CityInfoProvinceInfo]
ON [dbo].[CityInfo]
    ([ProvinceInfoID]);
GO

-- Creating foreign key on [AddressInfoID] in table 'ProvinceInfo'
ALTER TABLE [dbo].[ProvinceInfo]
ADD CONSTRAINT [FK_AddressInfoProvinceInfo]
    FOREIGN KEY ([AddressInfoID])
    REFERENCES [dbo].[AddressInfo]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AddressInfoProvinceInfo'
CREATE INDEX [IX_FK_AddressInfoProvinceInfo]
ON [dbo].[ProvinceInfo]
    ([AddressInfoID]);
GO

-- Creating foreign key on [AddressInfoID] in table 'CityInfo'
ALTER TABLE [dbo].[CityInfo]
ADD CONSTRAINT [FK_AddressInfoCityInfo]
    FOREIGN KEY ([AddressInfoID])
    REFERENCES [dbo].[AddressInfo]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AddressInfoCityInfo'
CREATE INDEX [IX_FK_AddressInfoCityInfo]
ON [dbo].[CityInfo]
    ([AddressInfoID]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------